package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IdCard;
import com.ruoyi.system.service.IIdCardService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 身份证Controller
 * 
 * @author ruoyi
 * @date 2024-10-15
 */
@Controller
@RequestMapping("/system/cz_card")
public class IdCardController extends BaseController
{
    private String prefix = "system/cz_card";

    @Autowired
    private IIdCardService idCardService;

    @RequiresPermissions("system:cz_card:view")
    @GetMapping()
    public String cz_card()
    {
        return prefix + "/cz_card";
    }

    /**
     * 查询身份证列表
     */
    @RequiresPermissions("system:cz_card:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IdCard idCard)
    {
        startPage();
        List<IdCard> list = idCardService.selectIdCardList(idCard);
        return getDataTable(list);
    }

    /**
     * 导出身份证列表
     */
    @RequiresPermissions("system:cz_card:export")
    @Log(title = "身份证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IdCard idCard)
    {
        List<IdCard> list = idCardService.selectIdCardList(idCard);
        ExcelUtil<IdCard> util = new ExcelUtil<IdCard>(IdCard.class);
        return util.exportExcel(list, "身份证数据");
    }

    /**
     * 新增身份证
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存身份证
     */
    @RequiresPermissions("system:cz_card:add")
    @Log(title = "身份证", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IdCard idCard)
    {
        return toAjax(idCardService.insertIdCard(idCard));
    }

    /**
     * 修改身份证
     */
    @RequiresPermissions("system:cz_card:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        IdCard idCard = idCardService.selectIdCardById(id);
        mmap.put("idCard", idCard);
        return prefix + "/edit";
    }

    /**
     * 修改保存身份证
     */
    @RequiresPermissions("system:cz_card:edit")
    @Log(title = "身份证", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IdCard idCard)
    {
        return toAjax(idCardService.updateIdCard(idCard));
    }

    /**
     * 删除身份证
     */
    @RequiresPermissions("system:cz_card:remove")
    @Log(title = "身份证", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(idCardService.deleteIdCardByIds(ids));
    }
}
